package com.yungu.swift.system.finance.dao;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.system.finance.model.dto.FinanceAccountSettlementDto;
import com.yungu.swift.system.finance.model.dto.FinanceActualFlowDto;
import com.yungu.swift.system.finance.model.param.AdminAccountSettlementPageParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public interface FinanceAccountSettlementMapper{

    @Update("update t_finance_account_settlement set settlement_status = 1,settlement_time = now() where uuid = #{uuid}")
    int settlementHandle(@Param("uuid") String uuid);


    @Select("select * from t_finance_account_settlement where uuid = #{uuid}")
    FinanceAccountSettlementDto get(@Param("uuid") String uuid);
    /**
     * 账户结算分页
     *
     * @param accountPageParam
     * @param pageBounds PageBounds
     * @return PageList<FinanceAccountSettlementDto>
     */
    @Select("select * from t_finance_account_settlement t where t.account_uuid = #{accountUuid} order by t.create_on desc")
    PageList<FinanceAccountSettlementDto> accountSettlementPage(AdminAccountSettlementPageParam accountPageParam, PageBounds pageBounds);

    /**
     * 统计
     * @param accountUuid
     * @return
     */
    @Select("select IFNULL(sum(case when t.settlement_status = 1 then t.settlement_amount else 0 end),0) as haveSettlementAmount," +
            "IFNULL(sum(case when t.settlement_status = 0 then t.settlement_amount else 0 end),0) AS canWithdrawAmount," +
            "count(1) as rowNum from t_finance_account_settlement t where t.account_uuid = #{accountUuid}")
    Map<String,Object> statistics(@Param("accountUuid") String accountUuid);
}
